import $ from 'jquery'

export default {
  name: 'public',
  date () {
    return {
      mapTooltip: '单击选中，再次单击下钻',
// 地图
      mapOption: {
        backgroundColor: '#fff',
        series: {
          type: 'map3D',
          map: 'hebei',
          itemStyle: {
            borderWidth: 2,
            borderColor: '#fff',
            color: '#aed9f9'
          },
          emphasis: {
            itemStyle: {
              color: '#5eb5ef'
            }
          },
          light: { // 光照阴影
            main: {
              color: '#fff', // 光照颜色
              intensity: 1, // 光照强度
              shadowQuality: 'high', // 阴影亮度
              shadow: true, // 是否显示阴影
              alpha: 45,
              beta: 0
            },
            ambient: {
              intensity: 0.3
            }
          },
          label: {
            show: false,
            textStyle: {
              color: '#000', // 地图初始化区域字体颜色
              fontSize: 16,
              opacity: 1,
              backgroundColor: 'rgba(0,23,11,0)'
              // backgroundColor: 'rgba(255,255,255,.1)'
            }
          },
          viewControl: {
            minBeta: -360,
            maxBeta: 360,
            center: [0, -20, 0],
            distance: 140,
            alpha: 45
          }
        },
        tooltip: {
          formatter: function (params) {
            let info = '<div style="font-size: 8px;">' + this.mapTooltip + '</div>'
            return info
          },
          backgroundColor: '#ff7f50',
          textStyle: {color: '#fff'}
        }
      },
      chartMap: {},
      geo_dim: '省',
      map_city: '',
      map_area: '全量小区',
      loading: $('#background,#progressBar'),
      service: {},
      cityName: '',
      now: new Date().setTime(new Date().getTime() - 24 * 60 * 60 * 1000),
      yesterday: this.now.getFullYear() + '-' + (this.now.getMonth() + 1) + '-' + this.now.getDate()
    }
  },
  methods: {

    GetDate (AddDayCount) {
      let dd = new Date()
      dd.setDate(dd.getDate() + AddDayCount)
      return dd.format('yyyy-MM-dd')
    },

    GetDateMore (type, AddCount, date) {
      let dd = new Date(this.getFormart(date))
      if (type === 'd') {
        dd.setDate(dd.getDate() + AddCount)
      } else if (type === 'm') {
        dd.setDate(dd.getMonth() + AddCount)
      } else if (type === 'y') {
        dd.setDate(dd.getFullYear() + AddCount)
      }
      return dd.format('yyyy-MM-dd')
    },

    getFormart (strDate) {
      if (strDate) {
        let date = $.eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
          function (a) {
            return parseInt(a, 10) - 1
          }).match(/\d+/g) + ')')
        return date
      } else {
        return null
      }
    },

    replaceNull (value) {
      if (value === null || value === 'null') {
        value = ''
      }
      return value
    },

    getData (type, data, fieds, pt) {
      const rdata = []
      if (type === 'pie') {
        $.each(data, function (i) {
          rdata.push({name: data[i][fieds[0]], y: data[i][fieds[1]]})
        })
        return rdata
      } else if (type === 'table') {
        $.each(data, function (i) {
          let cdata = data[i]
          if (pt) {
            if (cdata.col3 === pt) {
              rdata.push(cdata)
            }
          } else {
            rdata.push(cdata)
          }
        })
        return rdata
      } else {
        let cate = []
        let name = fieds[0]
        let val = fieds[1]
        $.each(data, function (i) {
          let cdata = data[i]
          if (pt) {
            if (cdata.col3 === pt) {
              cate.push(cdata[name])
              rdata.push(cdata[val])
            }
          } else {
            cate.push(cdata[name])
            rdata.push(cdata[val])
          }
        })

        return {cate: cate, data: rdata}
      }
    },

    // 直方图
    drawColumnCol (column, callback) {
      if (!column.marginTop) {
        column.marginTop = 5
      }
      if (column.cate.length > 15) {
        column.rotation = 90
        if (!isNaN(parseInt(column.cate[0])) && parseInt(column.cate[0]) === 1) {
          column.rotation = 0
        }
      }
      if (!column.rotation) {
        column.rotation = 0
      }
      if (column.lenabled) {
        column.lenabled = true
      } else {
        column.lenabled = false
      }
      if (!column.unit0) {
        column.unit0 = ''
      }
      if (!column.unit) {
        column.unit = ''
      }
      if (!column.leftYTitle) {
        column.leftYTitle = ''
      }
      if (!column.rightYTitle) {
        column.rightYTitle = ''
      }
      if (isNaN(column.leftYMin)) {
        column.leftYMin = null
      }
      if (isNaN(column.leftYMax)) {
        column.leftYMax = null
      }
      if (isNaN(column.rightYMin)) {
        column.rightYMin = null
      }
      if (isNaN(column.rightYMax)) {
        column.rightYMax = null
      }
      if (!column.marker) {
        column.marker = false
      }
      if (!column.height) {
        column.height = null
      }
      if (!column.width) {
        column.width = null
      }
      if (!column.inverted) {
        column.inverted = false
      }
      let highChart = this.ECharts.chart(column.id, {
        chart: {
          height: column.height,
          width: column.width,
          backgroundColor: 'rgba(0,0,0,0)',
          type: column.chartType,
          inverted: column.inverted
        },
        title: {
          text: column.title,
          align: 'center',
          x: 0,
          y: 2
        },
        xAxis: [{
          categories: column.cate,
          gridLineWidth: column.XWidth ? column.XWidth : '1',
          crosshair: true,
          labels: {
            rotation: column.rotation
          }
        }],
        yAxis: column.data.length > 1 ? [{
          min: column.Yfloor, // column.YMin?column.YMin:"0",
          // max:column.YMax,
          ceiling: column.Yceiling,
          gridLineWidth: column.YWidth ? column.YWidth : '0',
          title: {
            text: column.Ytitle
          }
        },
          {
            min: column.Yfloor2, // column.YMin?column.YMin:"0",
            // max:column.YMax,
            ceiling: column.Yceiling,
            gridLineWidth: column.YWidth ? column.YWidth : '0',
            title: {
              text: column.Ytitle
            },
            opposite: true
          }] : {
          // min:column.YMin?column.YMin:"0",
          // max:column.YMax,
          floor: column.Yfloor,
          ceiling: column.Yceiling,
          gridLineWidth: column.YWidth ? column.YWidth : '0',

          title: {
            text: column.Ytitle
          }
        },
        tooltip: {
          pointFormat: '<span style="color:{series.color}">{series.name}</span>: {point.y} <br/>',
          shared: true
        },
        legend: {
          // width:column.lenabledWidth,
          maxHeight: column.maxHeight,
          enabled: column.lenabled,
          align: column.lenabledAlign ? column.lenabledAlign : 'right',
          verticalAlign: column.lenabledVerticalAlign ? column.lenabledVerticalAlign : 'top',
          layout: column.layout, // "horizontal" 或 "vertical"
          y: column.legendY ? column.legendY : 6,
          x: column.legendX ? column.legendX : 0,
          itemHoverStyle: {
            color: '#74a7e4'
          },
          itemStyle: {
            fontSize: '8px',
            fontWeight: 'normal'
          },
          itemDistance: column.itemDistance,
          itemMarginTop: column.itemMarginTop,
          itemMarginBottom: column.itemMarginBottom
        },
        plotOptions: {
          column: {
            stacking: null,
            borderWidth: 0
          },
          series: {
            cursor: 'pointer',
            marker: {
              enabled: column.marker
            },
            events: {
              click: function (e) {
                if (column.seriesCallBack) {
                  column.seriesCallBack(this, e)
                }
              }
            }
          }
        },
        series: column.data
      })
      highChart.showLoading()
      highChart.reflow()
      highChart.hideLoading()
    },

    // 直方图Max
    drawColumnColMax (column, callback) {
      if (!column.marginTop) {
        column.marginTop = 5
      }
      if (column.cate.length > 15) {
        column.rotation = 90
        if (!isNaN(parseInt(column.cate[0])) && parseInt(column.cate[0]) === 1) {
          column.rotation = 0
        }
      }
      if (!column.rotation) {
        column.rotation = 0
      }
      if (column.lenabled) {
        column.lenabled = true
      } else {
        column.lenabled = false
      }
      if (!column.unit0) {
        column.unit0 = ''
      }
      if (!column.unit) {
        column.unit = ''
      }
      if (!column.leftYTitle) {
        column.leftYTitle = ''
      }
      if (!column.rightYTitle) {
        column.rightYTitle = ''
      }
      if (isNaN(column.leftYMin)) {
        column.leftYMin = null
      }
      if (isNaN(column.leftYMax)) {
        column.leftYMax = null
      }
      if (isNaN(column.rightYMin)) {
        column.rightYMin = null
      }
      if (isNaN(column.rightYMax)) {
        column.rightYMax = null
      }
      if (!column.marker) {
        column.marker = false
      }
      if (!column.height) {
        column.height = null
      }
      if (!column.width) {
        column.width = null
      }
      if (!column.inverted) {
        column.inverted = false
      }
      let highChart = this.ECharts.chart(column.id, {
        chart: {
          height: column.height,
          width: column.width,
          backgroundColor: 'rgba(0,0,0,0)',
          type: column.chartType,
          inverted: column.inverted
        },
        title: {
          text: column.title,
          align: 'center',
          x: 0,
          y: 2
        },
        xAxis: [{
          categories: column.cate,
          gridLineWidth: column.XWidth ? column.XWidth : '1',
          crosshair: true,
          labels: {
            rotation: column.rotation
          }
        }],
        yAxis: column.data.length > 1 ? [{
          min: column.Yfloor, // column.YMin?column.YMin:"0",
          max: column.YMax,
          // softMax: column.YsoftMax,
          // floor: column.Yfloor,
          ceiling: column.Yceiling,
          gridLineWidth: column.YWidth ? column.YWidth : '0',
          title: {
            text: column.Ytitle
          }
        },
          {
            min: column.Yfloor2, // column.YMin?column.YMin:"0",
            max: column.YMax2,
            // floor: column.Yfloor2,// ===0 ? column.Yfloor2 : column.Yfloor,
            ceiling: column.Yceiling,
            gridLineWidth: column.YWidth ? column.YWidth : '0',
            title: {
              text: column.Ytitle
            },
            opposite: true
          }] : {
          // min:column.YMin?column.YMin:"0",
          max: column.YMax,
          floor: column.Yfloor,
          ceiling: column.Yceiling,
          gridLineWidth: column.YWidth ? column.YWidth : '0',

          title: {
            text: column.Ytitle
          }
        },
        tooltip: {
          pointFormat: '<span style="color:{series.color}">{series.name}</span>: {point.y} <br/>',
          shared: true
        },
        legend: {
          // width:column.lenabledWidth,
          maxHeight: column.maxHeight,
          enabled: column.lenabled,
          align: column.lenabledAlign ? column.lenabledAlign : 'right',
          verticalAlign: column.lenabledVerticalAlign ? column.lenabledVerticalAlign : 'top',
          layout: column.layout, // "horizontal" 或 "vertical"
          y: column.legendY ? column.legendY : 6,
          x: column.legendX ? column.legendX : 0,
          itemHoverStyle: {
            color: '#74a7e4'
          },
          itemStyle: {
            fontSize: '8px',
            fontWeight: 'normal'
          },
          itemDistance: column.itemDistance,
          itemMarginTop: column.itemMarginTop,
          itemMarginBottom: column.itemMarginBottom
        },
        plotOptions: {
          column: {
            stacking: null,
            borderWidth: 0
          },
          series: {
            cursor: 'pointer',
            marker: {
              enabled: column.marker
            },
            events: {
              click: function (e) {
                if (column.seriesCallBack) {
                  column.seriesCallBack(this, e)
                }
              }
            }
          }
        },
        series: column.data
      })
      highChart.showLoading()
      highChart.reflow()
      highChart.hideLoading()
    },

    drawLineCol (line, callback) {
      if (!line.marginTop) {
        line.marginTop = 50
      }
      if (!line.rotation) {
        line.rotation = 0
      }
      if (line.lenabled) {
        line.lenabled = true
      } else {
        line.lenabled = false
      }
      if (!line.unit0) {
        line.unit0 = ''
      }
      if (!line.unit) {
        line.unit = ''
      }
      if (!line.leftYTitle) {
        line.leftYTitle = ''
      }
      if (!line.rightYTitle) {
        line.rightYTitle = ''
      }
      if (isNaN(line.leftYMin)) {
        line.leftYMin = null
      }
      if (isNaN(line.leftYMax)) {
        line.leftYMax = null
      }
      if (isNaN(line.rightYMin)) {
        line.rightYMin = null
      }
      if (isNaN(line.rightYMax)) {
        line.rightYMax = null
      }
      if (!line.marker) {
        line.marker = false
      }
      if (!line.height) {
        line.height = null
      }
      if (!line.width) {
        line.width = null
      }
      $('#' + line.id).highcharts({
        chart: {
          height: line.height,
          width: line.width,
          backgroundColor: 'rgba(0,0,0,0)',
          marginTop: line.marginTop,
          events: {
            click: function (e) {
              if (callback) {
                callback(e)
              }
            }
          }
        },
        title: {
          text: line.title,
          align: 'center',
          x: 0,
          y: 2
        },
        xAxis: [{
          categories: line.cate,
          crosshair: true,
          labels: {
            rotation: line.rotation
          }
        }],
        yAxis: [{ // Primary yAxis
          min: line.leftYMin,
          max: line.leftYMax,
          labels: {
            format: '{value}' + line.unit0
          },
          title: {
            text: line.leftYTitle
          }
        }, { // Secondary yAxis
          // min:0,
          min: line.rightYMin,
          max: line.rightYMax,
          title: {
            text: line.rightYTitle
          },
          labels: {
            format: '{value}' + line.unit
          },
          opposite: true
        }],
        tooltip: {
          pointFormat: '<span style="color:{series.color}">{series.name}</span>: {point.y} <br/>',
          shared: true
        },
        legend: {
          enabled: line.lenabled,
          align: line.lenabledAlign ? line.lenabledAlign : 'right',
          verticalAlign: line.lenabledVerticalAlign ? line.lenabledVerticalAlign : 'top',
          y: 10,
          x: 0,
          itemHoverStyle: {
            color: '#74a7e4'
          }
          // borderWidth: 1
        },
        plotOptions: {
          column: {
            stacking: 'normal',
            borderWidth: 0
          },
          series: {
            cursor: 'pointer',
            marker: {
              enabled: line.marker
            },
            events: {
              click: function (e) {
                if (line.seriesCallBack) {
                  line.seriesCallBack(this, e)
                }
              }
            }
          }
        },
        series: line.data
      })
    },

    // 饼图
    drawPie (pie, callback) {
      // htmlid, width, size, title, serie, data, callback,layout,align,marginRight,verticalAlign
      if (!pie.verticalAlign) {
        pie.verticalAlign = 'bottom'
      }
      if (!pie.layout) {
        pie.layout = 'horizontal'
      }
      if (!pie.align) {
        pie.align = 'center'
      }
      if (!pie.marginRight) {
        pie.marginRight = 50
      }
      // let highCharts =
      this.ECharts.chart(pie.id, {
        chart: {
          width: pie.width,
          plotBackgroundColor: null,
          plotBorderWidth: null,
          plotShadow: false,
          // marginRight : pie.marginRight,
          // // marginLeft : 20,
          // marginTop : pie.marginTop?pie.marginTop:12,
          // marginBottom : pie.marginBottom?pie.marginBottom:-8,
          backgroundColor: 'rgba(0,0,0,0)',
          events: {
            click: function (e) {
              if (callback) {
                callback(e)
              }
            }
          },
          type: pie.type
        },
        credits: {
          enabled: false // 禁用版权信息
        },
        title: {
          text: pie.title,
          floating: true,
          x: pie.titleX,
          style: {
            fontSize: '10px',
            font: 'bold 10px PingFangSC-Regular, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", 微软雅黑, Arial, sans-serif'
          }
          // y:10,
          // verticalAlign : 'top',
          // align:'center'
        },
        legend: {
          layout: pie.layout,
          align: pie.align,
          verticalAlign: pie.verticalAlign,
          itemStyle: {
            color: '#999',
            fontSize: '8px'
            // fontWeight: "",
          },
          itemWidth: pie.itemWidth
          // itemMarginTop:5,
        },
        // tooltip : {
        //     // pointFormat : '{series.name}: {point.y} <br/>占<b>{point.percentage:.1f}%</b>',
        //     pointFormat : '<b>{point.z}</b> <br/>占<b>{point.percentage:.1f}%</b>',
        //     // style : {
        //     //     fontFamily : "微软雅黑"
        //     // }
        // },
        tooltip: {
          headerFormat: '',
          pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {point.name}</b><br/>' +
            '数值: <b>{point.y}</b>'
        },
        plotOptions: {
          pie: {
            // allowPointSelect : true,
            // cursor : 'pointer',
            dataLabels: {
              enabled: pie.dataLabelsEnable ? pie.dataLabelsEnable : false,
              format: '<b>{point.name}</b>: {point.y:.2f} %',
              style: {
                color: (this.ECharts.theme && this.ECharts.theme.contrastTextColor) || 'black'
              }
            },
            size: pie.size,
            showInLegend: true,
            events: {
              click: function (event) {
                if (!callback || typeof callback === 'undefined' || callback === undefined) {
                  return
                }
                callback(event)
              }
            }
          },
          variablepie: {
            // allowPointSelect : true,
            // cursor : 'pointer',
            dataLabels: {
              enabled: false
            },
            size: pie.size,
            showInLegend: true,
            events: {
              click: function (event) {
                if (!callback || typeof callback === 'undefined' || callback === undefined) {
                  return
                }
                callback(event)
              }
            }
          }
        },
        series: [{
          type: 'pie',
          name: pie.serie,
          colorByPoint: true,
          /* dataLabels : {
              formatter : function() {
                  return this.y > 1 ? '<b>' + this.point.name + ': ' + this.point.percentage.toFixed(2) + ' %</b>' : null;
              }
          }, */
          minPointSize: 10,
          innerSize: '20%',
          zMin: 0,
          data: pie.data
        }]
      }, callback)
    },

    // 仪表盘
    drawGauge (gauge) {
      if (!gauge.plotBands) {
        gauge.plotBands = [{
          from: 0,
          to: 3
          // color: N.Util.Theme_colors.red // green
        }, {
          from: 3,
          to: 4
          // color: N.Util.Theme_colors.orange// yellow
        }, {
          from: 4,
          to: 5
          // color: N.Util.Theme_colors.green// red
        }]
      }
      $('#' + gauge.id).highcharts({
        chart: {
          type: 'gauge'
        },
        title: {
          text: gauge.title,
          align: 'left',
          margin: 0
        },
        pane: {
          center: ['50%', '100%'],
          size: '150%',
          startAngle: -90,
          endAngle: 90,
          background: null

        },
        tooltip: {
          enabled: true
        },
        yAxis: {
          min: 0,
          max: 5,
          minorTickInterval: 'auto',
          minorTickWidth: 2,
          minorTickLength: 5,
          minorTickPosition: 'inside',
          minorTickColor: '#fff',
          tickPixelInterval: 50,
          tickWidth: 2,
          tickPosition: 'inside',
          tickLength: 10,
          tickColor: '#fff',
          labels: {
            step: 2,
            rotation: 'auto'
          },
          title: {
            text: ''
          },
          borderWidth: 0,
          plotBands: gauge.plotBands
        },
        plotOptions: {
          gauge: {
            dataLabels: {
              y: 0,
              align: 'center',
              borderWidth: 0,
              useHTML: true
            },
            dial: {
              borderWidth: 1,
              borderColor: '#6890d4',
              backgroundColor: '#6890d4',
              radius: '100%'
            },
            pivot: {
              radius: 6,
              borderWidth: 1,
              borderColor: '#6890d4',
              backgroundColor: '#6890d4'
            }
          }
        },
        series: gauge.series
      })
    },

    getFormatNumber (i) {
      if (typeof i === 'number') {
        return i.toFixed(2)
      } else if (i === null) {
        return ''
      } else {
        return i
      }
    },

    // 校验是否全是数字
    ChkNum: function (str) {
    //	let patrn = /^\d+$/;
      let patrn = /^(-)?\d+(\.\d+)?$/
      return patrn.test(str)
    },

    getBasePath () {
      let obj = window.location
      let contextPath = obj.pathname.split('/')[1]
      let basePath = obj.protocol + '//' + obj.host + '/' + contextPath + '/'
      return basePath
    },

    getApiPath () {
      let obj = window.location
      return obj.protocol + '//' + obj.host + '/'
    },

    // 页面跳转
    /*page_query () {
      let yemian = $('#yemian').val()
      window.location.href = this.getBasePath() + yemian
      this.pageSelectOption(yemian)
    },*/

    switch_geography () {
      if ($('#showFont').hasClass('btn-no')) {
        $('#showFont').removeClass('btn-no').addClass('btn-yes').attr('geography', 'true')
      } else {
        $('#showFont').removeClass('btn-yes').addClass('btn-no').attr('geography', '')
      }
    },

    getCookie (name) {
      let cookies = document.cookie
      let list = cookies.split('; ') // 解析出名/值对列表

      for (let i = 0; i < list.length; i++) {
        let arr = list[i].split('=') // 解析出名和值
        if (arr[0] === name) {
          return decodeURIComponent(arr[1])
        }// 对cookie值解码
      }
      return ''
    },

    mapClick (params) {
      let geography = $('#showFont').attr('geography')
      let shiduan = $('#shiduan').val()
      if (!params) {
        this.geo_dim = '地市'
        this.map_city = this.chartMap.getOption().series[0].map
        return
      }
      if (params.data.label && params.data.label.show && this.chartMap.getOption().series[0].map === 'hebei') { // 下钻
        this.geo_dim = '地市'
        this.map_city = params.data.name
        this.chartMap.off('click', this.mapClick)
        this.chartMap.dispose()
        this.chartMap = this.ECharts.init(document.getElementById('map1'))
        this.mapOption.series.map = params.data.name
        // mapOption.tooltip.show = false;
        this.mapTooltip = '单击选中，单击右上角按钮返回'
        this.chartMap.setOption(this.mapOption)
        this.chartMap.on('click', this.mapClick)
      } else if ((params.data.label && !params.data.label.show) || (!params.data.label)) {
        $.each(this.chartMap.getOption().series[0].data, function (index, value) {
          if (value.label && value.label.show) {
            this.chartMap.setOption({
              series: {
                data: [{
                  name: value.name,
                  itemStyle: {
                    color: '#aed9f9'
                  },
                  label: {
                    show: false
                  }
                }]
              }
            })
          }
        })
        if (this.chartMap.getOption().series[0].map === 'hebei') { // 如果是省，设置地市
          this.geo_dim = '地市'
          this.map_city = params.data.name
        } else {
          this.geo_dim = '区县'
          this.map_area = params.data.name
        }
        this.chartMap.setOption({
          series: {
            data: [{
              name: params.data.name,
              itemStyle: {
                color: '#5eb5ef'
              },
              label: {
                show: true
              }
            }]
          }
        })
        if (!params.data.label || !params.data.label.show) {
          $(document).trigger('map:click', [geography, shiduan, this.geo_dim, this.map_city, this.map_area])
        }
      }
    },

    pageSelectOption (yemian) {
      $("select option[value='" + yemian + "']").attr('selected', 'selected')
    },

    // 新增千位符
    toThousands (num) {
          let num1 = (num || 0).toString()
          let result = ''
          let numTmp = num1
          let isCludes = false
          if (num1.includes('.')) {
            num1 = num1.split('.')[0]
            isCludes = true
          }
          while (num1.length > 3) {
            result = ',' + num1.slice(-3) + result
            num1 = num1.slice(0, num1.length - 3)
          }
          if (num1) { result = num1 + result }
          if (isCludes) {
            result = result + '.' + numTmp.split('.')[1]
          }
          return result
        },

    // 新增数据补齐两位小数
    returnFloat (value) {
      let val = Math.round(parseFloat(value) * 100) / 100
      let xsd = val.toString().split('.')
      if (xsd.length === 1) {
        val = val.toString() + '.00'
        return val
      }
      if (xsd.length > 1) {
        if (xsd[1].length < 2) {
          val = val.toString() + '0'
        }
        return val
      }
    },

    // 根据对象属性排序
    compare (list, property, sort) {
      for (let i = 0; i < list.length - 1; i++) {
        let a = list[i]
        let b = list[i + 1]
        return this.sortwithProperty(a, b, property, sort)
      }
    },

        sortWithProperty (a, b, property, sort) {
          let value1 = a[property]
          let value2 = b[property]
          if (sort) {
            // 降序
            return value1 - value2
          } else {
            return value2 - value1
          }
        },
    /* selectExportDate (type, param) {
      layer.typeTem = type
      layer.paramTem = param
      // iframe层
      layer.open({
        type: 2,
        title: '请选择导出日期',
        shadeClose: true,
        maxmin: true,
        shade: 0.8,
        area: ['30%', '50%'],
        content: '/view/selectdate' // iframe的url
      })
    }, */

    // 根据类型导出清单
    exportDetails (type, param) {
      let reqUrl = this.getApiPath() + 'view/pc/export/detail/excel'
      let geography = $('#showFont').attr('geography')
      console.log('时间维度:' + param.time_dim + '；地理纬度:' + param.geo_dim + '；省:' + this.HB_province + '；市:' + param.city + '；区县:' + param.area + '；请求地址:' + reqUrl)

      param.geography = geography
      param.type = type

      console.log('请求的参数为: ')
      console.log(param)
      // return;
      this.$service.post(reqUrl, param, {responseType: 'blob', timeout: 60 * 60 * 1000}).then(
        function (res) {
          let blob = new Blob([res.data], {type: 'application/vnd.ms-excel;charset=utf-8'}) // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
          let filename = decodeURIComponent(res.headers.filename)
          if ('download' in document.createElement('a')) {
            let downloadElement = document.createElement('a')
            let href = ''
            if (window.URL) href = window.URL.createObjectURL(blob)
            else href = window.webkitURL.createObjectURL(blob)
            downloadElement.href = href
            downloadElement.download = filename
            document.body.appendChild(downloadElement)
            downloadElement.click()
            if (window.URL) window.URL.revokeObjectURL(href)
            else window.webkitURL.revokeObjectURL(href)
            document.body.removeChild(downloadElement)
          } else {
            navigator.msSaveBlob(blob, filename)
          }
        }
      ).catch(function (reason) {
      })
    },

    // 页面各表格根据时间维度变更
    changeTitleByTimeDim () {
      let shiduan = $('#shiduan').val()
      if (shiduan === 'D') {
        shiduan = '天'
      } else if (shiduan === 'W') {
        shiduan = '周'
      } else if (shiduan === 'M') {
        shiduan = '月'
      } else {
        shiduan = '天'
      }
      let $timeDim = $('.timeDim')
      for (let i = 0; i < $timeDim.length; i++) {
        $timeDim[i].innerHTML = '(' + shiduan + ')'
      }
    },

    /**
     * 精确计算
     * */
    /**
     * 加法函数，用来得到精确的加法结果
     * @param {Object} arg1
     * @param {Object} arg2
     */
    accAdd (arg1, arg2) {
      let r1 = this.deal(arg1)
      let r2 = this.deal(arg2)
      let m = Math.pow(10, Math.max(r1, r2))
      return (arg1 * m + arg2 * m) / m
    },

    /**
     * 乘法函数，用来得到精确的乘法结果
     * @param {Object} arg1
     * @param {Object} arg2
     */
    accMul (arg1, arg2) {
      let m = 0
      m += this.deal(arg1)
      m += this.deal(arg2)
      let r1 = Number(arg1.toString().replace('.', ''))
      let r2 = Number(arg2.toString().replace('.', ''))
      return (r1 * r2) / Math.pow(10, m)
    },

    /**
     * 除法函数，用来得到精确的除法结果
     * @param {Object} arg1
     * @param {Object} arg2
     */
    accDiv (arg1, arg2) {
      let t1 = this.deal(arg1)
      let t2 = this.deal(arg2)
      let r1 = Number(arg1.toString().replace('.', ''))
      let r2 = Number(arg2.toString().replace('.', ''))
      return ((r1 / r2) * Math.pow(10, t2 - t1)).toFixed(2)
    },

    /**
     * 求小数点后的数据长度
     */
    deal (arg) {
      let t = 0
      try {
        t = arg.toString().split('.')[1].length
      } catch (e) {
      }
      return t
    }
    // 精确计算 结束


        /* $('#shiduan').change(function () {
      let geography = $('#showFont').attr('geography')
      let shiduan = $('#shiduan').val()
      $(document).trigger('map:click', [geography, shiduan, geo_dim, map_city, map_area])
      changeTitleByTimeDim()
    })

    $('#zhishi').change(function () {
      let geography = $('#showFont').attr('geography')
      let shiduan = $('#shiduan').val()

      $(document).trigger('map:click', [geography, shiduan, geo_dim, map_city, map_area])
    })

    $('#zhanxing').change(function () {
      let geography = $('#showFont').attr('geography')
      let shiduan = $('#shiduan').val()
      $(document).trigger('map:click', [geography, shiduan, geo_dim, map_city, map_area])
    })


    $('#showFont').click(function () {
      switch_geography()
      let geography = $('#showFont').attr('geography')
      let shiduan = $('#shiduan').val()
      $(document).trigger('map:click', [geography, shiduan, geo_dim, map_city, map_area])
    }) */
},
  mounted () {

  },
  created: function () {
  document.title = $('#yemian').find('option:selected')[0].text
  this.$service.get(
    'public/getCityName'
  ).then(function (value) {
    this.cityName = decodeURIComponent(value.data.cityName)
    if (!this.cityName) {
      alert('登陆人员所属城市为空，请重新登陆')
      return
    }
    console.log(this.cityName)
    this.mapOption.series.map = this.cityName
    this.chartMap = this.ECharts.init(document.getElementById('map1'))
    this.cityName === 'hebei' ? this.mapTooltip = this.mapTooltip : this.mapTooltip = '单击选中'
    this.chartMap.setOption(this.mapOption)
    window.resize = this.chartMap.resize
    this.chartMap.on('click', this.mapClick)
    if (this.cityName !== 'hebei') {
      this.mapClick()
    }
    this.chartMap.hideLoading()
    if (this.vcityName === 'hebei') {
      this.pageLoad('', 'D', '省', undefined, '全量小区')
    } else {
      this.pageLoad('', 'D', '地市', this.cityName, '全量小区')
    }
  }).catch(function (e) {
  })

  this.changeTitleByTimeDim()
}
}
